package com.itheima.hotel.service.impl;

import com.itheima.hotel.data.HotelData;
import com.itheima.hotel.data.RoomsData;
import com.itheima.hotel.service.HotelMgtSystem;

import java.time.LocalDateTime;
import java.util.*;

/*
业务层
 */
public class HotelMgtSystemImpl implements HotelMgtSystem {
    HotelData hotelData = new HotelData();

    private Map<RoomsData, LocalDateTime> map = new TreeMap<RoomsData, LocalDateTime>();

    private List<RoomsData> roomsDataList = hotelData.getRoomsDataList();

    /*
    订房
     */
    @Override
    public void reserveRoom() {

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入预定的房间号");
        String num = scanner.next();
        for (RoomsData roomsData : roomsDataList) {
            if (roomsData.isReserved() != true) {
                if (roomsData.getRoomNumber().equals(num)) {
                    roomsData.setReserved(true);
                    LocalDateTime time = getTime();
                    map.put(roomsData, time);

                }
            }
        }

    }


    /*
       退房
        */
    @Override
    public void checkOut() {

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入预定的房间号");
        String num = scanner.next();
        for (RoomsData roomsData : roomsDataList) {
            if (roomsData.isReserved() != false) {
                roomsData.setReserved(false);
                System.out.println("退房成功");
                map.remove(roomsData);
                return;
            }
        }

        System.out.println("当前房间不存在");
    }


    /*
    查询所有房间信息
     */
    @Override
    public void printAllRooms() {
        // List<RoomsData> roomsDataList = hotelData.getRoomsDataList();
     /*   Collections.sort(roomsDataList,(s1,s2)->{
            (int )(s1.getRoomNumber().compareTo()-s2.getRoomNumber());
        });*/
        for (RoomsData roomsData : roomsDataList) {
            System.out.println(roomsData.toString());
            System.out.println();
        }

    }

    /*
    查询预定房间信息
     */
    @Override
    public void printOderRooms() {
        map.forEach((key, values) -> {
            System.out.println("预定的房间信息为： " + key.toString() + " ;预定时间为: " + values);
        });

    }

    /*
    获取当前时间信息
     */
    public static LocalDateTime getTime() {
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("当前时间为 " + localDateTime);
        return localDateTime;

    }
}
